Learn R Programming

VeryLargeIntegers (version 0.1.8)

08. Modular-arithmetic: Basic Modular-Arithmetic Operators for vli Objects

Description

Basic modular-arithmetic operators for vli (Very Large Integers) objects.

Usage

summod(x, y, mod)

# S3 method for default summod(x, y, mod)

# S3 method for numeric summod(x, y, mod)

# S3 method for vli summod(x, y, mod)

submod(x, y, mod)

# S3 method for default submod(x, y, mod)

# S3 method for numeric submod(x, y, mod)

# S3 method for vli submod(x, y, mod)

mulmod(x, y, mod)

# S3 method for default mulmod(x, y, mod)

# S3 method for numeric mulmod(x, y, mod)

# S3 method for vli mulmod(x, y, mod)

powmod(x, n, mod)

# S3 method for default powmod(x, n, mod)

# S3 method for numeric powmod(x, n, mod)

# S3 method for vli powmod(x, n, mod)

invmod(x, n)

# S3 method for default invmod(x, n)

# S3 method for numeric invmod(x, n)

# S3 method for vli invmod(x, n)

divmod(x, y, mod)

# S3 method for default divmod(x, y, mod)

# S3 method for numeric divmod(x, y, mod)

# S3 method for vli divmod(x, y, mod)

Value

object of class vli

Arguments

x

vli class object or 32 bits integer

y

vli class object or 32 bits integer

mod

vli class object or 32 bits integer

n

vli class object or 32 bits integer

Author

Javier Leiva Cuadrado

Details

The functions summod, submod and mulmod compute respectively the sum, the substraction and the multiplication of x and y under modulo mod.

The function powmod computes the n-th power of x under modulo mod.

The function invmod returns the modular multiplicative inverse of x in Zn; that is, y = x^(-1) such that x * y = 1 (mod n).

The function divmod returns the modular division of x over y; that is, z such that y * z (mod mod) = x (mod mod).

Examples

Run this code
x <- as.vli("8925378246957826904701")
y <- as.vli("347892325634785693")
mod <- as.vli(21341)

summod(x, y, mod)

mulmod(x, invmod(x, n = 123), mod = 123) == 1

z <- divmod(x, y, mod)
mulmod(z, y, mod) == x %% mod

Run the code above in your browser using DataLab